package com.mairuide.importAnalysisDemo;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mairuide._frame.utils.JsonUtil;
import com.mairuide.one_click_search.dao.DataSourceDao;
import com.mairuide.one_click_search.pojo.DataSource;
import org.jasypt.encryption.StringEncryptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * Created by 敲代码的卡卡罗特
 * on 2018/12/9 23:28.
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class test {
    @Resource
    private DataSourceDao dataSourceDao;
    @Resource
    private RestTemplate restTemplate;
    @Test
    public void makeData() throws Exception{
        Map forObject = restTemplate.getForObject("https://www.easy-mock.com/mock/5bf8200de22c0172fbbdee1d/demo/yhmb#!method=get", Map.class);
        ObjectMapper mapper = new ObjectMapper();
        String string = mapper.writeValueAsString(forObject.get("rows"));
        List<DataSource> userListObj2= JsonUtil.string2Obj(string, List.class, DataSource.class);
        for (int i = 0; i < userListObj2.size(); i++) {
            dataSourceDao.save(userListObj2.get(i));
            System.out.println(JsonUtil.obj2String(userListObj2.get(i)));
        }
    }

    @Test
    public void test() throws Exception{
        /* Map<String, String> map = new HashMap<>();
         map.put("ids","460138240000027875,460138240000027953");
         Map forObject = restTemplate.postForObject("http://47.105.197.249:8888/base-site/call/list",map, Map.class);
         System.out.println(forObject);*/
        //System.out.println(org.apache.commons.lang3.StringUtils.isNotBlank(new Object));
     }

   /* @Test
    public void test() throws Exception{
        *//*String str="2018-12-01";
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
        Date date =sdf.parse(str);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH,1);
        Date time = calendar.getTime();
        System.out.println(sdf.format(time));
        System.out.println(time.getTime()==time.getTime());*//*

       *//* List<String> dateSlot = CalendarUtils.getDateSlot("2018-11-29", "2018-12-09");
        System.out.println(dateSlot);
        List dateAndHourList = ConstantPool.getDateAndHourList(dateSlot);
        System.out.println(dateAndHourList);*//*

        ArrayList<Object> list = new ArrayList<>();
        System.out.println(Double.valueOf("1.2")>Double.valueOf("1.1"));
    }
*/
   @Autowired
   StringEncryptor encryptor;
   @Test
   public void contextLoads() {
//       String username = encryptor.encrypt("bill");
//       System.out.println(username);        //加密123
//       String password = encryptor.encrypt("bill2018");
//       System.out.println(password);
       String time = encryptor.encrypt("2019-07-01");
       String kHnvZ2NBHeE5qzRMDntFBd89rr1pFvyK = encryptor.decrypt("5Een0FE89Z+wDPjmEFa+d2hw+HXnZTL1");
       System.out.println(kHnvZ2NBHeE5qzRMDntFBd89rr1pFvyK);

   }


    @Test
    public  void getLocalMac() throws SocketException {
       String s="交易日期 ,交易时间,摘要描述 ,借贷方标志,交易金额,账户余额,存期,交易机构号,交易机构名称,对方账号,对方户名,柜员号,交易渠道,交易流水号";
        String[] split = s.split(",");
        List<String> list = Arrays.asList(split);
        ArrayList<String> l = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            String s1 = list.get(i);
            l.add(s1.replaceAll("\\s*", ""));
        }
        System.out.println("llll"+l);
        List<Object> collect = list.stream().map(m -> {
            System.out.println(m.toString().trim());
            return m.toString().replaceAll("\\s*", "");
        }).collect(Collectors.toList());
        System.out.println(collect);
        System.out.println("交易日期 ".trim());
        String sss="序\n" +
                "号,11 22";
        System.out.println(sss.replaceAll("\r|\n", ""));
        System.out.println(sss.equals("序\n" +
                "号"));
        System.out.println("交易日期 ".replaceAll("\\s", ""));
        System.out.println("交易日期 ".replaceAll(" ", ""));
    }

    @Test
    public void aaa() {
      String s="2018-12-12 00:00:00";
      System.out.println(s.substring(0,10));

    }
}
